<template>
	<view class="list-container">
		<!-- 电影类型 -->
		<view class="list-type">
			<!-- 标题 -->
			<view class="list-title">
				<text class="title">{{filmList[0].title}}</text>
			</view>
			<!-- 电影列表项 -->
			<view class="list-list">
				<!-- 电影每一项 -->
				<film-item v-for="(item1,index1) in filmList[0].list" :key='index1' :film='item1' class="list-item"></film-item>	
			</view>
		</view>
		<!-- 加载更多 -->
		<loading></loading>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				filmList:[],
				pageIndex:1
			};
		},
		methods:{
			// 获取影院热映请求
			async getHotFilm(){
				await uni.request({
					url:'https://m.douban.com/rexxar/api/v2/subject_collection/movie_showing/items?pageindex='+this.pageIndex,
					method:"GET",
					data:{
						start:0,
						count:12
					}
				}).then(res=>{
					console.log(res[1].data)
					const type={
						title:res[1].data.subject_collection.name,
						list:res[1].data.subject_collection_items,
						id:res[1].data.subject_collection.id
					}
					this.filmList.push(type)
				}).catch(err=>err)
				
			},
			// 获取近期热门请求
			async getLatestFilm(){
				await uni.request({
					url:'https://m.douban.com/rexxar/api/v2/subject_collection/movie_latest/items',
					method:"GET",
					data:{
						start:0,
						count:12
					}
				}).then(res=>{
					console.log(res[1].data)
					const type1={
						title:res[1].data.subject_collection.name,
						list:res[1].data.subject_collection_items,
						id:res[1].data.subject_collection.id
					}
					this.filmList.push(type1)
				}).catch(err=>err)
				
			},
			// 获取免费电影请求
			async getFreeFilm(){
				await uni.request({
					url:'https://m.douban.com/rexxar/api/v2/subject_collection/movie_free_stream/items',
					method:"GET",
					data:{
						start:0,
						count:12
					}
				}).then(res=>{
					console.log(res[1].data)
					const type2={
						title:res[1].data.subject_collection.name,
						list:res[1].data.subject_collection_items,
						id:res[1].data.subject_collection.id
					}
					this.filmList.push(type2)
				}).catch(err=>err)
			},
			// 跳转更多
			// goToList(item){
			// 	uni.navigateTo({
			// 		url:'../../subpkg/filmList/filmList?id='+item.id
			// 	})
			// }
		},
		onLoad(options) {
			
			if(options.id=='movie_showing'){
				this.getHotFilm()
			}
			if(options.id=='movie_latest'){
				this.getLatestFilm()
			}
			if(options.id=='movie_free_stream'){
				this.getFreeFilm()
			}
			
		},
		onReachBottom(){
			console.log('到底了')
			// this.filmList=[...this.filmList,res[1].data]
			this.getHotFilm()
			this.pageIndex++
		}
	}
</script>

<style lang="scss">
.list-container{
	// 电影类型
	.list-type{
		background-color: #FFFFFF;
		margin-bottom: 20rpx;
		//标题
		.list-title{
			padding: 26rpx 0;
			font-size: 28rpx;
			font-weight: bold;
			.title{
				padding-left: 26rpx;
				border-left: 8rpx solid #42bd56;
			}
			.more{
				float: right;
				margin-right: 30rpx;
				color: #42bd56;
			}
		}
		//电影列表项
		.list-list{
			width: 100%;
			display: flex;
			flex-wrap: wrap;
			padding: 0 12rpx;
			box-sizing: border-box;
			//电影每一项
			.list-item{
				width: 33.33%;
				padding: 0 20rpx;
				box-sizing: border-box;
				margin-bottom: 20rpx;
				// border: 1px solid red;
			}
		}
	}
}
</style>
